<?php 
require_once('../connections/con_gl.php');
$awal = $_GET['awal'];
$akhir = $_GET['akhir'];
$jumlah = $akhir - $awal;

?>

<br />
<table width="100%" border="1" cellspacing="0" cellpadding="3">
	<tr style="background-color:#eee;text-align:center;">
		<th rowspan="2">No.</th>
		<th rowspan="2">Jenis Kendaraan</th>
		<th colspan="<?php echo $jumlah+1; ?>">Data Stock Kendaraan Rental</th>
	</tr>
	<tr style="background-color:#eee;text-align:center;">
		<?php
		for($i=$awal; $i<=$akhir; $i++){
			echo "<th>$i</th>";
		}
		?>
	</tr>
    
	<?php
    $query = mysql_query("SELECT DISTINCT a.tipekendaraan FROM gl_masterkendaraan as a inner join gl_tipekendaraan as b on (a.tipekendaraan = b.id)") or die (mysql_error());
	$no=1;
	while(list($tipekend) = mysql_fetch_row($query)){
		list($namakend) = mysql_fetch_row(mysql_query("SELECT tipekendaraan FROM gl_tipekendaraan WHERE id = '$tipekend'"));		
		echo "<tr>";
		echo "<td align='center'>$no.</td>";
		echo "<td align='left'>$namakend</td>";
		for($i=$awal; $i<=$akhir; $i++){
			list($jmltahun) = mysql_fetch_row(mysql_query("SELECT COUNT(tahun) FROM gl_masterkendaraan WHERE tipekendaraan = '$tipekend' AND tahun = '$i'")); 
			if($jmltahun == '0') $jmltahun = '';
			
			echo "<td align='center'>$jmltahun</td>";
		}
		
	echo "</tr>";	
		$no++;
	}
	
	?>
	
    <td colspan="2" align="center"><b>Total</b></td>
		<?php
		 
		$total = array();
	$query = mysql_query("SELECT DISTINCT a.tipekendaraan FROM gl_masterkendaraan as a inner join gl_tipekendaraan as b on (a.tipekendaraan = b.id)") or die (mysql_error());
	$no=1;
	while(list($tipekend) = mysql_fetch_row($query)){
		list($namakend) = mysql_fetch_row(mysql_query("SELECT tipekendaraan FROM gl_tipekendaraan WHERE id = '$tipekend'"));		
		
		for($i=$awal; $i<=$akhir; $i++){
			list($jmltahun) = mysql_fetch_row(mysql_query("SELECT COUNT(tahun) FROM gl_masterkendaraan WHERE tipekendaraan = '$tipekend' AND tahun = '$i'")); 
			if($jmltahun == '0') $jmltahun = '';
			$total[$i] =$jmltahun;		
		}				
		
		$no++;
	}
	for($i=$awal; $i<=$akhir; $i++){
				list($jml) = mysql_fetch_row(mysql_query("SELECT COUNT(tahun) FROM gl_masterkendaraan WHERE tahun = '$i'")); 
			echo "<td align='center'>$jml</td>";
	}
			
		?>
		
	</tr>
</table>

<p>&nbsp;</p>